﻿using UnityEngine;
using System.Collections;


public class Player : MonoBehaviour
{
    public int Hp;
    public int HpMax;
    public int Protecting = 0;
    PlaneMove move;
    Bullet gun;
    GameObject upgrade;
    GameObject Shield;
    GameObject shield_1;
    Transform wuqi;
    Transform hudun;
    Bullet bullet;
    // Use this for initialization
    void Start()
    {
        Hp = HpMax;
        move = GetComponent<PlaneMove>();
        gun = GetComponent<Bullet>();
        upgrade = Resources.Load<GameObject>("FX/levelup");
        Shield = Resources.Load<GameObject>("FX/shield");
        shield_1= Resources.Load<GameObject>("FX/shield_1");
        wuqi = GameObject.Find("Plane").transform;
        hudun = GameObject.Find("Plane").transform;
    }

    public void AddProp(PropType type)
    {
        switch (type)
        {
            case PropType.Life:
                Hp += (int)(HpMax * 0.5f);
                break;
            case PropType.weapon:
                GameObject fx = Instantiate(upgrade,wuqi)as GameObject;
                fx.transform.position = transform.position+new Vector3(0,-0.6f);
                Destroy(fx, 1f);
                gun.LeveUp();
               
                break;
            case PropType.Protect:
               
                GameObject go = Instantiate(Shield, hudun) as GameObject;
                go.transform.position = transform.position;
                Protecting++;
                ShowProtectView();
                break;
            default:
                break;
        }
    }
    public void OnDamage(int damage)
    {
        if (Protecting > 0)
        {
            Protecting--;
            ShowProtectView();
        }
        else
        {
            Hp -= damage;
            if (Hp <= 0)
            {
                Debug.Log("死亡");
            }
        }
    }
    void ShowProtectView()
    {
        if (Protecting > 0)
        {

        }
        else
        {

        }
    }
    
}
